<?php
namespace App\Http\Controllers\Admin;

use App\Service\Admin\ProService;
use App\Utility\Upload;
use Illuminate\Http\Request;

class ProController extends BaseController
{
    //项目

    //列表
    public function index(Request $request)
    {
        $pages['start'] = $request->post('start', 1);
        $pages['limit'] = $request->post('limit', 10);
        $pas['shop_id'] = $request->post('shop_id', 0);
        $res = ProService::index($pages, $pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data'], $res['total']);
    }

    //修改
    public function modify(Request $request)
    {
        $id = $request->post('id', 0);
        $pas['title'] = $request->post('title', '');
        $pas['shop_id'] = $request->post('shop_id', 0);
        $pas['cost'] = $request->post('cost', 0) * 100;
        $pas['money'] = $request->post('money', '') * 100;
        if ($id) {
            $res = ProService::modify($id, $pas);
        } else {
            $res = ProService::add($pas);
        }
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }

    //删除
    public function del(Request $request)
    {
        $id = $request->post('id', 0);
        $res = ProService::del($id);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }

    //开工
    public function go(Request $request)
    {
        $id = $request->post('id', 0);
        $res = ProService::go($id);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }

    //完成
    public function finish(Request $request)
    {
        $id = $request->post('id', 0);
        $res = ProService::finish($id);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }
}